package HomeWork.hw2;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author Administrator
 * @Date 2020/5/21 13:45
 **/

@WebServlet("/refreshDemo")
public class RefreshDemo extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /*1.页面上显示文字信息：输出流写数据
        * 2.5s后跳转：设置响应头
        * 3.跳转超链接*/

        /*响应乱码处理：*/
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter pw=resp.getWriter();
        pw.write("支付成功，正在跳转");
        pw.write("<a href='http://localhost:8080/web/hw/refreshDemo.html'> 若未跳转，点击这里</a>");

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.sendRedirect("/web/redirectDemo2");
    }
}
